<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> 
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    
	
	<title>_${customer.customerName}_出库信息</title>
	<script type="text/javascript">
	var datatable_content;
	var filterParam = {};
	 
        $(function() {
		    $("#queryForm").validate(); 
			$("#fromDate").datepicker({ format : 'yyyy-mm-dd' });
			$("#toDate").datepicker({ format : 'yyyy-mm-dd' });
       });
       
       function initTable() {
           datatable_content = $("#contentTable").dataTable({
               "bServerSide": true,
               "sAjaxSource": '${ctx}/outstorageInfo_1/v2_queryOutstorageInfo',
               "fnServerData": callback,
               "fnRowCallback": rowCallBack,
               "bFilter": false,
               "aLengthMenu": [20, 50, 100],
               "bSort": false,
               "sZeroRecords": "查询无记录！",
               "bProcessing": true,
               "oLanguage": {
                   "sUrl": '${ctx}/static/v2/js/plugins/datatables/cn.txt'
               },
               "scrollX": true,
               "autoWidth": false,
               "aoColumns": [{
                   "mData": null
               }, {
                   "mData": "customerName",
                   "sDefaultContent": ""
               }, {
                   "mData": "groupName",
                   "sDefaultContent": ""
               }, {
                   "mData": "sku",
                   "sDefaultContent": ""
               }, {
                   "mData": "goodsName",
                   "sDefaultContent": ""
               }, {
                   "mData": "normalNum",
                   "sDefaultContent": ""
               }, {
                   "mData": "ulOrderNum",
                   "sDefaultContent": ""
               }, {
                   "mData": "recallNum",
                   "sDefaultContent": ""
               }, {
                   "mData": "exceptionNum",
                   "sDefaultContent": ""
               }, {
                   "mData": "allotNum",
                   "sDefaultContent": ""
               }, {
                   "mData": "saleNum",
                   "sDefaultContent": ""
               }, {
                   "mData": "returnNum",
                   "sDefaultContent": ""
               }, {
                   "mData": "num",
                   "sDefaultContent": ""
               }]
           });
       }

       function query() {
           //验证，如果选了时间必须选时间类型
           if ($("#queryForm").valid()) {
               if (datatable_content) {
                   datatable_content.fnDestroy();
               }
               initTable();
           }
       }

       /**
        *构造查询条件
        */
       function callback(sSource, aoData, fnCallback) {
         	//initFormData();
           var formParam = $("#queryForm").serializeArray();
           for (var n in filterParam) {
               formParam.push(filterParam[n]);
           }
           var jsondata=arrayToJson(aoData.concat(formParam));
           $.ajax({
               "type": "post",
               "url": sSource,
               "dataType": "json",
               "data": jsondata,
               "success": fnCallback
           });
       }
       
       /**
        *创建了行的回调
        *nRow为当前的tr
        */
       function rowCallBack(nRow, aData, iDisplayIndex, iDisplayIndexFull) {
           var iDisplayStart = datatable_content.fnSettings()._iDisplayStart;
           $("td:eq(0)", nRow).html(iDisplayStart + iDisplayIndex + 1);
       }
       
       /**
       *	将json数组转换为json对象
       */
       function arrayToJson(array) {
       	var jsonParam = {};
           for (var i = 0; i < array.length; i++) {
           	jsonParam[array[i].name] = array[i].value;
         	}
         	return jsonParam;
     	}
        
	//订单明细
	function detail_order(){
	   $("#queryForm").attr("action","${ctx}/outstorageInfo_1/v2_queryDetail_order");
	   $("#queryForm").submit();
	}
	
/* 	//查询
	function query(){
	   $("#queryForm").attr("action","${ctx}/outstorageInfo_1/v2_queryOutstorageInfo");
	   $("#queryForm").submit();
	} */
	
	//拣货明细
	function detail_work(){
	   $("#queryForm").attr("action","${ctx}/outstorageInfo_1/v2_queryDetail_work");
	   $("#queryForm").submit();
	}
	
	 //导出Excel
     function exportExcel(){
       $("#queryForm").attr("action","${ctx}/outstorageInfo_1/expTotal");
     }
     
     //级联商家店铺
	 function loadShop(customerCode,sel_shop){
		  $("#"+sel_shop).html("");
		  $.ajax({
				type : 'post',
				url : '${ctx}/warehouse/ajaxGetShop',
				data : {
					customerCode:customerCode
				},
				dataType : 'json',
				success : function(data) {
				    var shopList=data.shopList;
				    var str="<option value='' selected='selected'></option>";
					$.each(shopList, function(i) {
					    var shop=shopList[i];
					    str+="<option value='"+shop.shopCode+"'>"+shop.shopName+"</option>";
					});
					$("#"+sel_shop).html(str);
					$("#"+sel_shop).trigger("chosen:updated");
				},
				error : function() {
					alert("网络繁忙，请稍后重试...");
				}
			});
	  }
	    
	  
    </script>
</head>

<body>
<section class="content">
<div class="row">
		<div class="col-md-12">

			<!-- Primary box -->
			<div class="box box-solid box-primary">
				<div class="box-header">
					<i class="fa fa-search"></i>
					<h3 class="box-title">搜索栏</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
				<div class="box-body">
	<form class="form-search" id="queryForm" action="${ctx}/outstorageInfo_1/v2_queryOutstorageInfo" method="post">
	<div class="form-group row">
			<div class="col-sm-3">
				<div class="input-group col-sm-12">
			    <label class="input-group-text">商家名称：</label>
				 <select  name="customerCode"  id="customerCode" value="${_customerCode}"  class="form-control required" onchange="ajaxAreaGroup(this,'_warehouseCode');loadShop(this.value,'_shopCode');">
					<option value=""></option>
					<c:forEach items="${customerList}" var="customer">
						<option value="${customer.customerCode}"
						<c:if test="${_customerCode eq customer.customerCode}">selected=selected</c:if>
						>${customer.customerName}</option>
					</c:forEach>
				</select>
				</div>
				</div>
				
				
			<div class="col-sm-3">
				<div class="input-group col-sm-12">
				<label class="input-group-text">仓库名称：</label>
				<select  name="warehouseCode"  id="warehouseCode" value="${_warehouseCode}" class="form-control">
					<option value=""></option>
					<c:forEach items="${warehouseList}" var="wm">
						<option value="${wm.groupCode}"
						<c:if test="${_warehouseCode eq wm.groupCode}">selected=selected</c:if>
						>${wm.groupName}</option>
					</c:forEach>
				</select>
				</div>
				</div>
				
			<div class="col-sm-3">
				<div class="input-group col-sm-12">
				<label class="input-group-text">销售店铺:</label>
				<select class="form-control"  id="shopCode" name="shopCode"  value="${param._shopCode}"  >
				        <option value=""></option>
						<c:forEach items="${shopList}" var="shop">
							<option value="${shop.shopCode}"
							  <c:if test="${param._shopCode eq shop.shopCode }">selected=selected</c:if>
							>${shop.shopName}</option>
						</c:forEach>
				</select> 
				</div>
				</div>
				
				<div class="col-sm-3">
				<div class="input-group col-sm-12">
				<label class="input-group-text">作业批次：</label> 
				<input  name="batchCode"  id="batchCode" value="${_batchCode}"  class="form-control" />
				</div>
				</div>
		</div>
				
		<div class="form-group row">
			<div class="col-sm-3">
				<div class="input-group col-sm-12">
				<label class="input-group-text">出库日期：</label> 
			 	<input type="text" name="fromDate" id="fromDate"  class="form-control required" value="${_fromDate}" /> 
			</div>
			</div>	
				
			<div class="col-sm-3">
				<div class="input-group col-sm-12">
				<label class="input-group-text">至：</label> 
			 	<input type="text" name="toDate" id="toDate" class="form-control required" value="${_toDate}"/> 
			</div>
			</div>
			
			<div class="col-sm-3">
				<div class="input-group col-sm-12">	
				<label class="input-group-text">SKU编号：</label> 
				<input  name="sku"  id="sku" value="${_sku}" class="form-control" />
			 </div>
			 </div>
			 </div>
			 
			    
			    <div class="form-group row">
			<div class="col-sm-4">
				<div class="input-group col-sm-12">	
			    <button type="button" onclick="query();" class="btn btn-info ">查询</button>
			    <button class="btn btn-primary" type="submit" onclick="exportExcel();">导出Excel</button>
			    <button class="btn btn-primary"  onclick="detail_order();">订单明细</button>
			    <button class="btn btn-primary"  onclick="detail_work();">拣货明细</button>
			    </div>
			    </div>
			    </div>
			    
	 </form>
	</div>
	</div>
	</div>
	</div>
	
	
	<div class="row">
		<div class="col-md-12">

			<!-- Primary box -->
			<div class="box box-solid box-primary">
				<div class="box-header">
					<i class="fa fa-list"></i>
					<h3 class="box-title">查询结果</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
				<div class="box-body">
	<table id="contentTable" class="table table-striped table-bordered table-condensed">
		<thead><tr>
		    <th style="width: 50px;">序列</th>
		    <th style="width: 80px;">商家</th>
		    <th style="width: 80px;">仓库</th>
		    <th style="width: 140px;">SKU</th>
		    <th >商品名称</th>
		    <th style="width: 80px;">订单数</th>
		    <th style="width: 80px;">线下单数</th>
		    <th style="width: 80px;">重发单数</th>
		    <th style="width: 80px;">异常单数</th>
		    <th style="width: 80px;">调拨数</th>
		    <th style="width: 80px;">销售数</th>
		    <th style="width: 80px;">返厂数</th>
			<th style="width: 80px;">出库合计</th>
		</tr></thead>
		<%-- <tbody>
		
		<c:if test="${empty dtoList or dtoList.size() eq 0}">
	       <tr><td colspan="13" height="50" style="vertical-align:middle; text-align: center;color: gray;font-size: 20px;">无数据</td></tr>
	    </c:if>
		
		<c:if test="${not empty dtoList}">
		<c:forEach items="${dtoList}" var="dto" varStatus="i">
			<tr>
			   <td>${i.count}</td>
			   <td>${dto.customer.customerName}</td>
			   <td>${dto.warehouse.groupName}</td>
			   <td>${dto.sku}</td>
			   <td>${dto.goodsName}</td>
			   <td>${dto.normalNum}</td>
			   <td>${dto.ulOrderNum}</td>
			   <td>${dto.recallNum}</td>
			   <td>${dto.exceptionNum}</td>
			   <td>${dto.allotNum}</td>
			   <td>${dto.saleNum}</td>
			   <td>${dto.returnNum}</td>
			   <td>${dto.num}</td>
			</tr>
		</c:forEach>
		</c:if>
		
		</tbody> --%>
	</table>
	</div>
	</div>
	</div>
	</div>
</section>	
</body>
</html>
